﻿using MediatR;
using Microsoft.AspNetCore.Http.HttpResults;
using RBAC.Domain;
using RBAC.Domain.Service.Interfae;
using RBACDuYaJun.Api.Appliction.Command.MenuCommand;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace RBACDuYaJun.Api.Appliction.CommandHandlers.MenuHanders
{
    public class MenuUpdateCommandHandler : IRequestHandler<MenuUpdateCommand, int>
    {
        private readonly IMenuService _menuService;
        public MenuUpdateCommandHandler(IMenuService menuService)
        {
            _menuService = menuService;
        }
        public async Task<int> Handle(MenuUpdateCommand request, CancellationToken cancellationToken)
        {
            return await _menuService.UpdateMenu(new Menu()
            {
                MenuId = request.MenuId,
                MenuName = request.MenuName,
                MenuUrl = request.MenuUrl,
                MenuPid = request.MenuPid,
                MenuDelete = request.MenuDelete,
                CreateBy = request.CreateBy,
                CreateDate = request.CreateDate,
                UpdateBy = "王宏",
                UpdateDate = DateTime.Now
            });
        }
    }
}
